﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using FinancasMD.Models;
using System.Data.Entity;
using System.Net;

namespace FinancasMD.Controllers
{
    public class ContaController : Controller
    {
        //
        // GET: /Conta/

        private DBFinancasMDEntities db = new DBFinancasMDEntities();

        public ActionResult Index()
        {
            var conta = db.Conta;
            return View(conta);
        }

        public ActionResult Adicionar()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Adicionar(Conta conta)
        {
            if (ModelState.IsValid)
            {
                db.Conta.Add(conta);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(conta);
        }

        public ActionResult Editar(long id)
        {
            Conta conta = db.Conta.Find(id);

            return View(conta);
        }

        [HttpPost]
        public ActionResult Editar(Conta conta)
        {
            if (ModelState.IsValid)
            {
                db.Entry(conta).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(conta);
        }

        // GET: Movies/Delete/5
        public ActionResult Excluir(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            Conta conta = db.Conta.Find(id);
            if (conta == null)
            {
                return HttpNotFound();
            }
            return View(conta);
        }

        // POST: Movies/Delete/5
        [HttpPost, ActionName("Excluir")]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(int id)
        {
            Conta conta = db.Conta.Find(id);
            db.Conta.Remove(conta);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

    }
}
